<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            background-color: red;
        }
        p{
            background-color: yellow;
            width: 100px;
        }
    </style>
</head>
<body>
    <div>
        <p>文字
            <a href="http://www.baidu.com">百度</a>
        </p>
    </div>
    <script>
        let div = document.querySelector('div')
        let p = document.querySelector('p')

        div.onclick= function(){
            console.log('div');
            
        }
        p.onclick=function(e){
            // 基于事件对象组织冒泡
            e.stopPropagation()
            console.log(p);
            
        }
        let a = document.querySelector('a')
        a.onclick=function(e){
            // 阻止默认行为
            e.preventDefault()
        }
    </script>
</body>
</html>